<template>
	<view class="container">
		<view class="upload" v-if="avatar">
			<text>头像：</text>
			<view class="box">
			</view>
			<button type="default" @click="go">登录</button>
		</view>
		<view class="upload" v-else>
			<view class="box">
				<image class="box-img" :src="'http://localhost:8090/'+user.icon" @click="uploadiamge"></image>
			</view>
			<uni-list>
				<uni-list-item title="修改密码" note=""></uni-list-item>
				<uni-list-item title="电话" note="" :rightText="user.telephone"></uni-list-item>
			</uni-list>
			<button type="default" @click="exit">退出</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				avatar: true,
				user: {},
				a: '123',
			}
		},
		methods: {
			exit() {
				uni.removeStorage({
					key: 'user'
				})
				this.user = {},
					this.avatar = true
			},
			uploadiamge() {
				uni.chooseImage({
					count: 1,
					success: (res) => {
						uni.uploadFile({
							url: 'http://localhost:8090/foodapp/uploadheadicon',
							filePath: res.tempFilePaths[0],
							formData: {
								id: this.user.id
							},
							name: 'file',
							success: uploadFileRes => {
								console.log('uploadFileRes', uploadFileRes);
								this.user.icon=JSON.parse(uploadFileRes.data).headiconpath
							}
						});
					}
				})
			},
			go() {
				uni.navigateTo({
					url: '/pages/my/login/login'
				})
			},
			getUser() {
				uni.getStorage({
					key: 'user',
					success: res => {
						this.user = res.data
						this.avatar = false
					},
				});
			}
		},
		onShow() {
			console.log(this.avatar);
			this.getUser()
		}
	}
</script>

<style>
	.container {
			padding: 20px;
			font-size: 14px;
			line-height: 24px;
		}
	
		.box {
			width: 80px;
			height: 80px;
			border-radius: 50%;
			background-color: antiquewhite;
		}
		.box-img{
			width: 80px;
			height: 80px;
		}
</style>
